// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;

int t, n;

const int N = 1e6+ 50;

const LL INF = 1e18;

struct snode {
    int id;
    LL v;
    snode (int id=0, LL v=0):id(id), v(v) {}

    bool operator < (const snode &other) const {
        if (v != other.v) return v < other.v;
        else return id < other.id;
    }
};

// template<typename T>
typedef snode T;
struct segT {
    T dat[N << 2];
    LL lazy[N << 2];
    int nn;

    void init(int n) {
        nn = 1;
        while (nn < n)
            nn <<= 1;

        for (int i=1; i<=n; ++i)
            dat[i+nn-1] = snode(i, 0);
        for (int i=nn+n; i<2*nn; ++i)
            dat[i] = snode(-1, -INF);
        for (int i=nn-1; i>=0; --i)
            pu(i);
    }

    inline void pd(int rt) {
        if (lazy[rt]) {
            int ls = rt << 1, rs = rt << 1 | 1;
            dat[ls].v += lazy[rt];
            dat[rs].v += lazy[rt];
            lazy[ls] += lazy[rt];
            lazy[rs] += lazy[rt];
            lazy[rt] = 0;
        }
    }

    inline void pu(int rt) {
        dat[rt] = max(dat[rt<<1], dat[rt<<1|1]);
    }

    
    int L, R;

    void u(int l, int r, int rt, int v) {
        if (L <= l && r <= R) {
            dat[rt].v += v;
            lazy[rt] += v;
            return;
        }
        int m = (l+r) >> 1;
        pd(rt);
        if (L <= m) u(l, m, rt<<1, v);
        if (m+1<=R) u(m+1, r, rt<<1|1, v);
        pu(rt);
    }
    T q(int l, int r, int rt) {
        // dbg(l, r, rt, dat[rt].v);
        if (L <= l && r <= R) {
            return dat[rt];
        }
        int m = (l + r) >> 1; pd(rt);
        T v1 = snode(-1, -INF), v2 = snode(-1, -INF);
        if (L <= m) v1 = q(l, m, rt<<1);
        if (m+1<=R) v2 = q(m+1, r, rt<<1|1);
        pu(rt);
        return max(v1, v2);
    }
    void u(int l, int r, int x) {
        // dbg(l, r, x);
        L = l;
        R = r;
        u(1, nn, 1, x);
    }
    T q(int l, int r) {
        L = l;
        R = r;
        return q(1, nn, 1);
    }
};

segT seg;

struct node {
    int x, y, c, mx, mi;
    node(int x=0, int y=0, int c=0):x(x), y(y), c(c) {};
} dat[N];

static int disc[N * 3], dcnt;


struct rec {
    pair<int, int> st, ed;
};

int unique(int a[], int n) {
    int res = 0;
    for (int i=1, j; i<=n; i=j+1) {
        j = i;
        while (j+1<=n && a[j+1] == a[i]) ++j;
        a[++res] = a[i];
    }
    return res;
}

int stp[N], scnt;

int main(int argc, char const *argv[]) {
    // code
    scanf("%d", &n);
    for (int i=0; i<n; ++i) {
        scanf("%d%d%d", &dat[i].x, &dat[i].y, &dat[i].c);
    }

    {
        dcnt = 0;
        for (int i=0; i<n; ++i) {
            disc[++dcnt] = dat[i].y;
            disc[++dcnt] = dat[i].x;
        }
        disc[++dcnt] = 1000000001;
        sort(disc + 1, disc + dcnt + 1);
        // dcnt = unique(disc + 1, disc + dcnt + 1) - disc;
        dcnt = unique(disc, dcnt);

        seg.init(dcnt);

        for (int i=0; i<n; ++i) {
            dat[i].x = lower_bound(disc + 1, disc + dcnt + 1, dat[i].x) - disc;
            dat[i].y = lower_bound(disc + 1, disc + dcnt + 1, dat[i].y) - disc;

            int pos = max(dat[i].x, dat[i].y);
            dat[i].mx = pos;
            dat[i].mi = min(dat[i].x, dat[i].y);
            stp[++scnt] = dat[i].mx + 1;
            stp[++scnt] = dat[i].mi;
            seg.u(pos, dcnt, dat[i].c);
        }
        sort(stp+1,stp+1+scnt);
        scnt = unique(stp, scnt);

        // for (int i=1; i<=dcnt; ++i)
        //     dbg(i, disc[i]);
    }

    {
        sort(dat, dat+n, [](const node &a, const node &b) {
            return a.mi < b.mi;
        });



        for (int i=1; i<=dcnt; ++i)
            seg.u(i, dcnt, -(disc[i] - disc[i-1]));
    }   

    snode res = seg.q(1, dcnt);
    LL ans = res.v;
    rec ansr; ansr.st = make_pair(0, 0);
    ansr.ed = make_pair(disc[res.id], disc[res.id]);
    // dbg(ans, ansr.st.first, ansr.ed.first);
    
    // return 0;


        int now = 0;
    {
        for (int i=1; i<=scnt; ++i) {


            int st = stp[i];
            while (now < n && dat[now].mi < st) {
                seg.u(dat[now].mx, dcnt, -dat[now].c);
                // dbg(now, dat[now].x, dat[now].y);
                ++now;
            }

            // for (int i=1; i<=dcnt; ++i) 
            //     dbg(i, disc[i], seg.q(i, i).id, seg.q(i, i).v);
            LL tans = disc[st];
            snode res = seg.q(st, dcnt);
            tans += res.v;

            // dbg(st, dcnt, res.id, res.v, tans);

            if (tans > ans) {
                ans = tans;
                ansr.st = make_pair(disc[st], disc[st]);
                ansr.ed = make_pair(disc[res.id], disc[res.id]);
            }
        }
    }

    if (ans < 0) {
        puts("0\n2000000000 2000000000 2000000000 2000000000");
        return 0;
    }
    printf("%lld\n", ans);
    printf("%d %d %d %d\n", ansr.st.first, ansr.st.second, ansr.ed.first, ansr.ed.second);
    return 0;
}
